package net.goutalk.glcs.module.erpModel.caseErpCustomer.controller;

import cn.hutool.core.bean.BeanUtil;
import net.goutalk.glcs.common.annotation.GlcsLog;
import net.goutalk.glcs.common.constant.GlobalConstant;
import net.goutalk.glcs.common.model.result.R;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.dto.AddCaseErpCustomerGatherDetailDto;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.dto.UpdateCaseErpCustomerGatherDetailDto;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.entity.CaseErpCustomerGatherDetail;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.service.ICaseErpCustomerGatherDetailService;
import net.goutalk.glcs.module.erpModel.caseErpCustomer.vo.CaseErpCusGatherDetailInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 客户回款详情【case_erp_customer_gather_detail】 前端控制器
 * </p>
 *
 * @author hnyyzy
 * @since 2023-07-12
 */
@RestController
@RequestMapping(GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerGatherDetail")
@Api(value = GlobalConstant.CASE_ERP_CUSTOMER +"/caseErpCustomerGatherDetail", tags = "客户回款详情")
@AllArgsConstructor
public class CaseErpCustomerGatherDetailController {

    private ICaseErpCustomerGatherDetailService caseErpCustomerGatherDetailService;


    @PostMapping
    @ApiOperation(value = "新增客户回款详情信息")
    public R add(@Valid @RequestBody AddCaseErpCustomerGatherDetailDto dto) {
        return R.ok(caseErpCustomerGatherDetailService.add(dto));
    }

    @PutMapping
    @ApiOperation(value = "修改客户回款详情信息")
    public R update(@Valid @RequestBody UpdateCaseErpCustomerGatherDetailDto dto) {
        return R.ok(caseErpCustomerGatherDetailService.edit(dto));
    }

    @GetMapping(value = "/info")
    @ApiOperation(value = "根据id查询客户回款详情信息")
    public R info(@RequestParam Long id) {
        CaseErpCustomerGatherDetail caseErpCustomerGatherDetail = caseErpCustomerGatherDetailService.getById(id);
        if (caseErpCustomerGatherDetail == null) {
            R.error("找不到此客户回款详情信息！");
        }
        return R.ok(BeanUtil.toBean(caseErpCustomerGatherDetail, CaseErpCusGatherDetailInfo.class));
    }

    @DeleteMapping
    @ApiOperation(value = "删除")
    @GlcsLog(value = "删除客户回款详情信息")
    public R delete(@Valid @RequestBody Long id) {
        return R.ok(caseErpCustomerGatherDetailService.delete(id));
    }

}
